package main

import (
	"bytes"
	"fmt"
	"os"
)

/*
函数的延迟调用
*/

func main() {
	f, err := os.Open("filename")
	defer f.Close()
	if err != nil {
		fmt.Println(err)
	}
	//defer f.Close()

	var c []byte
	b := bytes.NewBuffer(c)
	content, _ := f.Read(b.Bytes())
	fmt.Println(content)

	//f.Close()

	x, y := 1, 2
	defer func(a int) {
		fmt.Println(a, x, y)
	}(11)

	fmt.Println(x, y+1)

	fmt.Println(testdefer())
}

func testdefer() int {
	a := 100
	defer func() {
		fmt.Println("defer", a)
		a += 100
	}()
	/*	temp:=a
		return temp*/
	return a
}
